import request from '@/utils/request';

export async function getInspectionFileInfoByPage(params: any) {
  return request('/api/quality/getInspectionFileInfoByPage', {
    method: 'POST',
    data: params,
  });
}

export async function addInspectionFileInfo(params: any) {
  return request('/api/quality/addInspectionFileInfo', {
    method: 'POST',
    data: params,
  });
}

export async function updateInspectionFileInfo(params: any) {
  return request('/api/quality/updateInspectionFileInfo', {
    method: 'POST',
    data: params,
  });
}

export async function delInspectionFileInfo(params: any) {
  return request('/api/quality/delInspectionFileInfo', {
    method: 'POST',
    data: params,
  });
}

export async function exportInspectionFileInfo(params: any) {
  return request('/api/quality/exportInspectionFileInfo', {
    method: 'POST',
    data: params,
    responseType: 'blob',
  });
}

// 上传检验附件
export async function uploadInspectionFileInfo(para: any) {
  return request('/api/quality/uploadInspectionFileInfo', {
    method: 'POST',
    requestType: 'form',
    data: para.file,
    headers: {
      'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundaryX72QZDdfwlF5U73J',
    },
    params: {
      id: para.id,
      inspectionType: para.inspectionType,
      uploadTime: para.uploadTime,
      uploaderId: para.uploaderId,
      uploaderName: para.uploaderName,
    },
  });
}

// 附件下载
export async function downloadInspectionFile(para: any) {
  return request('/api/quality/downloadInspectionFile', {
    method: 'GET',
    responseType: 'blob',
    params: {
      inspectionFileId: para.inspectionFileId,
    },
  });
}

// 获取当前用户
export async function viewBaseInfo(params: any) {
  return request('/api/user/viewBaseInfo', {
    method: 'POST',
    data: params,
  });
}

// 获取url
export async function getInspectPreviewUrl(params: any) {
  return request('/api/quality/getInspectPreviewUrl', {
    method: 'POST',
    data: params,
  });
}

export default {
  getInspectionFileInfoByPage,
  addInspectionFileInfo,
  updateInspectionFileInfo,
  delInspectionFileInfo,
  exportInspectionFileInfo,
};
